
#include "config/IncludeParts.h"

#if USE_BMP
#include "BmpReader.h"
#include <cstring>

using namespace unigame;

#pragma pack(2)

struct BmpHead
{
	uint16 m_type;
	uint32 m_fileSize;
	uint32 m_none;
	uint32 m_dataOffset;
};

struct BmpInfo
{
	uint32 m_headSize;
	uint32 m_width;
	uint32 m_height;
	uint16 m_planes;
	uint16 m_pixelBits;
	uint32 m_compress;
	uint32 m_dataSize;
	uint32 m_hResolution;
	uint32 m_vResolution;
	uint32 m_colors;
	uint32 m_importantColors;
};

bool BmpReader::read()
{
	if(m_fileDataLen <= sizeof(BmpHead) + sizeof(BmpInfo))
	{
		return false;
	}
	BmpHead bh;
	memcpy(&bh, m_fileData, sizeof(BmpHead));
	uint32 offset = sizeof(BmpHead);
	if(m_fileDataLen < bh.m_dataOffset)
	{
		return false;
	}
	BmpInfo bi;
	memcpy(&bi, m_fileData + offset, sizeof(BmpInfo));
	offset += sizeof(BmpInfo);
	if(offset < bh.m_dataOffset)
	{
	}
	m_width = bi.m_width;
	m_height = bi.m_height;
	switch(bi.m_compress)
	{
	case 0:
		readNoCompress(offset, bh.m_fileSize, bi.m_pixelBits);
		break;
	case 1:
		readRle4(offset, bh.m_fileSize);
		break;
	case 2:
		readRle8(offset, bh.m_fileSize);
		break;
	case 3:
		readBitFiled(offset, bh.m_fileSize);
		break;
	default:
		return false;
	}
	return true;
 }

void BmpReader::readNoCompress(uint32 offset, uint32 len, int32 bits)
{

}

void BmpReader::readRle4(uint32 offset, uint32 len)
{
}

void BmpReader::readRle8(uint32 offset, uint32 len)
{
}

void BmpReader::readBitFiled(uint32 offset, uint32 len)
{
}

#pragma pack()
#endif